

USE [WebSecurity]
GO

-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_UserProfile_dbo_Membership]') AND parent_object_id = OBJECT_ID(N'[dbo].[Membership]'))
ALTER TABLE [dbo].[Membership] DROP CONSTRAINT [fk_dbo_UserProfile_dbo_Membership]
GO
ALTER TABLE [dbo].[Membership]  WITH CHECK ADD  CONSTRAINT [fk_dbo_UserProfile_dbo_Membership] FOREIGN KEY([UserId])
REFERENCES [dbo].[UserProfile]([UserId])
GO
ALTER TABLE [dbo].[Membership] CHECK CONSTRAINT [fk_dbo_UserProfile_dbo_Membership]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_PasswordQuestion_dbo_Membership]') AND parent_object_id = OBJECT_ID(N'[dbo].[Membership]'))
ALTER TABLE [dbo].[Membership] DROP CONSTRAINT [fk_dbo_PasswordQuestion_dbo_Membership]
GO
ALTER TABLE [dbo].[Membership]  WITH CHECK ADD  CONSTRAINT [fk_dbo_PasswordQuestion_dbo_Membership] FOREIGN KEY([PasswordQuestionID])
REFERENCES [dbo].[PasswordQuestion]([PasswordQuestionID])
GO
ALTER TABLE [dbo].[Membership] CHECK CONSTRAINT [fk_dbo_PasswordQuestion_dbo_Membership]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_UserProfile_dbo_OAuthMembership]') AND parent_object_id = OBJECT_ID(N'[dbo].[OAuthMembership]'))
ALTER TABLE [dbo].[OAuthMembership] DROP CONSTRAINT [fk_dbo_UserProfile_dbo_OAuthMembership]
GO
ALTER TABLE [dbo].[OAuthMembership]  WITH CHECK ADD  CONSTRAINT [fk_dbo_UserProfile_dbo_OAuthMembership] FOREIGN KEY([UserId])
REFERENCES [dbo].[UserProfile]([UserId])
GO
ALTER TABLE [dbo].[OAuthMembership] CHECK CONSTRAINT [fk_dbo_UserProfile_dbo_OAuthMembership]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_Application_dbo_ApplicationRoles]') AND parent_object_id = OBJECT_ID(N'[dbo].[ApplicationRoles]'))
ALTER TABLE [dbo].[ApplicationRoles] DROP CONSTRAINT [fk_dbo_Application_dbo_ApplicationRoles]
GO
ALTER TABLE [dbo].[ApplicationRoles]  WITH CHECK ADD  CONSTRAINT [fk_dbo_Application_dbo_ApplicationRoles] FOREIGN KEY([ApplicationID])
REFERENCES [dbo].[Application]([ApplicationID])
GO
ALTER TABLE [dbo].[ApplicationRoles] CHECK CONSTRAINT [fk_dbo_Application_dbo_ApplicationRoles]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_UserProfile_dbo_UsersInRoles]') AND parent_object_id = OBJECT_ID(N'[dbo].[UsersInRoles]'))
ALTER TABLE [dbo].[UsersInRoles] DROP CONSTRAINT [fk_dbo_UserProfile_dbo_UsersInRoles]
GO
ALTER TABLE [dbo].[UsersInRoles]  WITH CHECK ADD  CONSTRAINT [fk_dbo_UserProfile_dbo_UsersInRoles] FOREIGN KEY([UserId])
REFERENCES [dbo].[UserProfile]([UserId])
GO
ALTER TABLE [dbo].[UsersInRoles] CHECK CONSTRAINT [fk_dbo_UserProfile_dbo_UsersInRoles]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_ApplicationRoles_dbo_UsersInRoles]') AND parent_object_id = OBJECT_ID(N'[dbo].[UsersInRoles]'))
ALTER TABLE [dbo].[UsersInRoles] DROP CONSTRAINT [fk_dbo_ApplicationRoles_dbo_UsersInRoles]
GO
ALTER TABLE [dbo].[UsersInRoles]  WITH CHECK ADD  CONSTRAINT [fk_dbo_ApplicationRoles_dbo_UsersInRoles] FOREIGN KEY([ApplicationRoleId])
REFERENCES [dbo].[ApplicationRoles]([ApplicationRoleId])
GO
ALTER TABLE [dbo].[UsersInRoles] CHECK CONSTRAINT [fk_dbo_ApplicationRoles_dbo_UsersInRoles]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_UserProfile_dbo_UserProfileData]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserProfileData]'))
ALTER TABLE [dbo].[UserProfileData] DROP CONSTRAINT [fk_dbo_UserProfile_dbo_UserProfileData]
GO
ALTER TABLE [dbo].[UserProfileData]  WITH CHECK ADD  CONSTRAINT [fk_dbo_UserProfile_dbo_UserProfileData] FOREIGN KEY([UserId])
REFERENCES [dbo].[UserProfile]([UserId])
GO
ALTER TABLE [dbo].[UserProfileData] CHECK CONSTRAINT [fk_dbo_UserProfile_dbo_UserProfileData]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_UserProfile_dbo_ApplicationUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[ApplicationUser]'))
ALTER TABLE [dbo].[ApplicationUser] DROP CONSTRAINT [fk_dbo_UserProfile_dbo_ApplicationUser]
GO
ALTER TABLE [dbo].[ApplicationUser]  WITH CHECK ADD  CONSTRAINT [fk_dbo_UserProfile_dbo_ApplicationUser] FOREIGN KEY([UserId])
REFERENCES [dbo].[UserProfile]([UserId])
GO
ALTER TABLE [dbo].[ApplicationUser] CHECK CONSTRAINT [fk_dbo_UserProfile_dbo_ApplicationUser]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_Application_dbo_ApplicationUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[ApplicationUser]'))
ALTER TABLE [dbo].[ApplicationUser] DROP CONSTRAINT [fk_dbo_Application_dbo_ApplicationUser]
GO
ALTER TABLE [dbo].[ApplicationUser]  WITH CHECK ADD  CONSTRAINT [fk_dbo_Application_dbo_ApplicationUser] FOREIGN KEY([ApplicationID])
REFERENCES [dbo].[Application]([ApplicationID])
GO
ALTER TABLE [dbo].[ApplicationUser] CHECK CONSTRAINT [fk_dbo_Application_dbo_ApplicationUser]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_Application_dbo_ApplicationProfileData]') AND parent_object_id = OBJECT_ID(N'[dbo].[ApplicationProfileData]'))
ALTER TABLE [dbo].[ApplicationProfileData] DROP CONSTRAINT [fk_dbo_Application_dbo_ApplicationProfileData]
GO
ALTER TABLE [dbo].[ApplicationProfileData]  WITH CHECK ADD  CONSTRAINT [fk_dbo_Application_dbo_ApplicationProfileData] FOREIGN KEY([ApplicationID])
REFERENCES [dbo].[Application]([ApplicationID])
GO
ALTER TABLE [dbo].[ApplicationProfileData] CHECK CONSTRAINT [fk_dbo_Application_dbo_ApplicationProfileData]
GO



